package com.chaoyue.base.utils;
/*
 * @description:
 * @author: liujian11
 * @date: 2020-07-29$
 */

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.format.FastDateFormat;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.util.Date;

public class ObjectUtils extends ObjectUtil {
    //<editor-fold desc="两对象值相等判断方法">

    /**
     * 检查两String对象是否值相等
     *
     * @param param1 参数1
     * @param param2 参数2
     * @return 是否值相等
     */
    public static boolean equals(CharSequence param1, CharSequence param2) {
        return StrUtils.equals(param1, param2);
    }

    /**
     * 检查两BigDecimal对象是否值相等
     *
     * @param param1 参数1
     * @param param2 参数2
     * @return 是否值相等
     */
    public static boolean equals(BigDecimal param1, BigDecimal param2) {
        return NumberUtil.equals(param1, param2);
    }

    /**
     * 检查两Date对象是否值相等
     *
     * @param param1 参数1
     * @param param2 参数2
     * @return 是否值相等
     */
    public static boolean equals(Date param1, Date param2) {
        return DateUtils.compare(param1, param2) == 0;
    }

    //</editor-fold>

    //<editor-fold desc="对象拷贝">
    public static void copy(Object source, Object target) {
        BeanUtils.copyProperties(source, target);
    }

    public static <T> T copy(Object source, Class<T> clazz) {
        T target = null;
        try {
            target = clazz.newInstance();
            BeanUtils.copyProperties(source, target);
        } catch (Exception ex) {

        }
        return target;
    }
    //</editor-fold>

    //<editor-fold desc="类型转换为字符串">
    public static String toString(BigDecimal target) {
        String result = "";
        if (target != null) {
            result = target.toString();
        }
        return result;
    }

    public static String toString(DateTime target) {
        String result = "";
        if (target != null) {
            result = DateUtils.format(target, DatePattern.NORM_DATETIME_FORMAT);
        }
        return result;
    }

    public static String toString(Date target) {
        String result = "";
        if (target != null) {
            result = DateUtils.format(target, DatePattern.NORM_DATE_FORMAT);
        }
        return result;
    }

    public static String toString(Date target, FastDateFormat pattern) {
        String result = "";
        if (target != null) {
            result = DateUtils.format(target, pattern);
        }
        return result;
    }
    //</editor-fold>

    // <editor-fold desc="获取JDBC执行数据">

    // </editor-fold>
}
